package us.mooresr.geartrack.server.handler;

import us.mooresr.geartrack.server.DAO;
import us.mooresr.geartrack.shared.action.PutLoanAction;
import us.mooresr.geartrack.shared.action.PutLoanResult;
import us.mooresr.geartrack.shared.model.Loan;

import com.gwtplatform.dispatch.server.ExecutionContext;
import com.gwtplatform.dispatch.server.actionhandler.ActionHandler;
import com.gwtplatform.dispatch.shared.ActionException;

public class PutLoanActionHandler implements ActionHandler<PutLoanAction, PutLoanResult> {

	@Override
	public PutLoanResult execute(PutLoanAction action, ExecutionContext arg1)
			throws ActionException {
		DAO dao = new DAO();
		
		Loan newLoan = action.getLoanIn();
		
		dao.ofy().put(newLoan);
		
		PutLoanResult result = new PutLoanResult(newLoan);
		
		return result;
	}

	@Override
	public Class<PutLoanAction> getActionType() {
		return PutLoanAction.class;
	}

	@Override
	public void undo(PutLoanAction arg0, PutLoanResult arg1,
			ExecutionContext arg2) throws ActionException {
		// TODO Auto-generated method stub
		
	}

}
